package com.ruoyi.swla2.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.swla2.domain.RealtimeGatherData;
import com.ruoyi.swla2.service.IRealtimeGatherDataService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 实时数据采集（大）Controller
 *
 * @author gdqt
 * @date 2023-09-05
 */
@RestController
@RequestMapping("/swla2/realtimeGatherData")
public class RealtimeGatherDataController extends BaseController {
    @Autowired
    private IRealtimeGatherDataService realtimegatherdataService;

    /**
     * 查询实时数据采集（大）列表
     */
    @PreAuthorize("@ss.hasPermi('swla2:terminalsFreeze:list')")
    @GetMapping("/list")
    public TableDataInfo list(RealtimeGatherData realtimegatherdata) {
        startPage();
        List<RealtimeGatherData> list = realtimegatherdataService.selectRealtimegatherdataList(realtimegatherdata);
        return getDataTable(list);
    }

    /**
     * 获取实时数据采集（大）详细信息
     */
    @PreAuthorize("@ss.hasPermi('swla2:terminalsFreeze:query')")
    @GetMapping(value = "/getByTerminalId")
    public AjaxResult getByTerminalId(@RequestParam("terminalId") String terminalId) {
        return success(realtimegatherdataService.selectRealtimegatherdataByTerminalId(terminalId));
    }

    /**
     * 导出实时数据采集（大）列表
     */
    @PreAuthorize("@ss.hasPermi('swla2:terminalsFreeze:export')")
    @Log(title = "实时数据采集（大）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RealtimeGatherData realtimegatherdata) {
        List<RealtimeGatherData> list = realtimegatherdataService.selectRealtimegatherdataList(realtimegatherdata);
        ExcelUtil<RealtimeGatherData> util = new ExcelUtil<RealtimeGatherData>(RealtimeGatherData.class);
        util.exportExcel(response, list, "实时数据采集（大）数据");
    }

    /**
     * 获取实时数据采集（大）详细信息
     */
    @PreAuthorize("@ss.hasPermi('swla2:terminalsFreeze:query')")
    @GetMapping(value = "/{tenantId}")
    public AjaxResult getInfo(@PathVariable("tenantId") String tenantId) {
        return success(realtimegatherdataService.selectRealtimegatherdataByTenantId(tenantId));
    }

    /**
     * 新增实时数据采集（大）
     */
    @PreAuthorize("@ss.hasPermi('swla2:terminalsFreeze:add')")
    @Log(title = "实时数据采集（大）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RealtimeGatherData realtimegatherdata) {
        realtimegatherdata.setTenantId(this.getTenantId());
        return toAjax(realtimegatherdataService.insertRealtimegatherdata(realtimegatherdata));
    }

    /**
     * 修改实时数据采集（大）
     */
    @PreAuthorize("@ss.hasPermi('swla2:terminalsFreeze:edit')")
    @Log(title = "实时数据采集（大）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RealtimeGatherData realtimegatherdata) {
        return toAjax(realtimegatherdataService.updateRealtimegatherdata(realtimegatherdata));
    }

    /**
     * 删除实时数据采集（大）
     */
    @PreAuthorize("@ss.hasPermi('swla2:terminalsFreeze:remove')")
    @Log(title = "实时数据采集（大）", businessType = BusinessType.DELETE)
    @DeleteMapping("/{tenantIds}")
    public AjaxResult remove(@PathVariable String[] tenantIds) {
        return toAjax(realtimegatherdataService.deleteRealtimegatherdataByTenantIds(tenantIds));
    }
}
